package br.com.cfccultura.admin.control.actions.utils;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.stereotype.Component;

import br.com.cfccultura.admin.control.actions.DefaultAction;
import br.com.cfccultura.admin.model.vo.ValueObject;
import br.com.cfccultura.admin.view.report.ReportManager;
import br.com.cfccultura.admin.view.report.ReportManager.Type;

@Component("/reportPrint")
public class ReportPrintAction extends DefaultAction {
	
	public ActionForward print(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		HashMap<String, Object> params = (HashMap<String, Object>) request.getSession().getAttribute("jasperParams");
		params.put("funcionario", getUsuario(request));
		
		List<ValueObject> beans = (List<ValueObject>)  request.getSession().getAttribute("jasperDs");
		
		Type type =(Type) request.getSession().getAttribute("reportType");	
		
		new ReportManager().print(type, response, params, beans);
		
		request.getSession().removeAttribute("jasperParams");
		request.getSession().removeAttribute("jasperDs");
		request.getSession().removeAttribute("reportType");
		return null;
	}

}
